package bubble;

/**
 * @program: thread
 * @description:冒泡排序
 * @author: gongj
 * @Description: TODO
 * @create: 2020-07-12 20:54
 **/
public class BubbleTest {
    public static void main(String[] args) {
        Integer[] arrs = {16,12,34,12,4949};
        BubbleTest.bubble(arrs);
    }
    public static void bubble(Integer[] arrs){
        System.out.println("长度为" + arrs.length);
        int count = 0;
        for (int i = 1; i < arrs.length; i++) {   //小于5 也就是i最大为4，循环四次
            for (int j = 0 ; j <= i-1 ;j++ ){  //
                if(arrs[j] > arrs[j+1]){
                    int temp = arrs[j];
                    arrs[j] = arrs[j+1];
                    arrs[j+1] =  temp;

                }
                count++;
            }
        }
        System.out.println(count);
        for (int i = 0; i < arrs.length; i++) {
            System.out.print(arrs[i] + "，");
        }
    }
}
